//
//  HMRemindItme.swift
//  HealthMonitoring
//
//  Created by 珠海正杰 on 2018/8/14.
//  Copyright © 2018年 YTYanK. All rights reserved.
//

import UIKit
import SwiftyJSON
/// 右
class HMREmindRinghtItme: UIView {
    let describe = UILabel()
    var heightItme:CGFloat =  0.0
    init(json: JSON, frame: CGRect) {
        super.init(frame: frame)
        setupViews(view: self, json: json)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupViews(view: UIView, json: JSON)  {
            view.addSubview(describe)
            describe.topAlign(view: view, predicate: "3")
            describe.leadingAlign(view: view, predicate: "10")
            describe.heightConstrain(predicate: "30")
            describe.width(view: view, predicate: "*0.15")
            describe.text =  json["describe"].stringValue
        
             let ary = json["arry"].arrayValue
        var iv: Int = 0
        for v in ary {
            let value = UILabel()
            value.tag = iv
            view.addSubview(value)
            let topStr = 3 + (iv * 30)
            value.topAlign(view: view, predicate: "\(topStr)")
            value.leadingHorizontally(view: describe, predicate: "0")
            value.heightConstrain(predicate: "30")
            value.trailingAlign(view: view)
            value.text =  v.stringValue
            iv += 1
        }
       self.heightItme = CGFloat(ary.count * 33)
    }
}


class HMRemindItme: UIView {
    var remindItmeHeight: CGFloat  = 0.0
    var json: JSON
    

    init(setItmeJson:JSON, frame: CGRect) {
        self.json = setItmeJson
        super.init(frame: frame)
         setupViews(view: self)
    }
    
    
    
    required init?(coder aDecoder: NSCoder) {
       fatalError("init(coder:) has not been implemented")
    }
    
    
    private func setupViews(view: UIView)  {

        
        // 单个餐，药的数量
        
        let a = self.json["A"].arrayValue
        let b = self.json["B"].arrayValue
        
        let front = HMREmindRinghtItme.init(json: ["describe" : "餐前:", "arry": a], frame: CGRect.init(x: 0, y: 0, width: 100, height: 100))
            view.addSubview(front)
            front.topAlign(view: view, predicate: "0")

            front.leadingAlign(view: view, predicate: "0")
            front.heightConstrain(predicate: "\(front.heightItme)")
            front.trailingAlign(view: view , predicate: "0")
        
        
        let after = HMREmindRinghtItme.init(json: ["describe": "餐后:", "arry": b],frame:  CGRect.init(x: 0, y: 0, width: 100, height: 100))
           view.addSubview(after)
           after.topVertically(view: front, predicate: "10")
           after.leadingAlign(view: view, predicate: "0")
           after.heightConstrain(predicate: "\(after.heightItme)")
           after.trailingAlign(view: view, predicate: "0")
           self.remindItmeHeight = front.heightItme + after.heightItme + 10.0
    }
    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */

}
